package com.macaline.concurrent.interrupt;

import java.util.concurrent.*;

public class Demo {

    public static void main(String[] args) {

        ExecutorService executorService = new ThreadPoolExecutor(
                3,
                4,
                2L,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(3),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy());

        Thread a = new Thread(() -> {
            while (true) {
                try {
                    System.out.println("A Thread print...");
                    TimeUnit.SECONDS.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    break;
                }
            }
        }, "A");
        a.start();
//        executorService.submit(a);


        System.out.println("调用A线程interrupt方法");
        a.interrupt();

        System.out.println("调用A线程isInterrupted方法，返回值为"+ a.isInterrupted());
        System.out.println("第二次调用A线程isInterrupted方法，返回值为"+ a.isInterrupted());

        System.err.println("主线程执行结束");
    }
}
